<?php
/*
 * @author : Pham Huu Sam
 * @phone : 0922.926.269
 */
class Login extends CI_Controller{
    //put your code here

    public function  __construct() {
        parent::__construct();
        $this->load->Model('Musers');
        $this->load->helper("url");
        $this->load->library("admin_login"); // Sử dụng thư viện layout
        $this->admin_login->setLayout("layout/admin_login"); // load file layout chính (view/layout/frontend.php)

    }

    // Controller mặc định cho trang chủ
    public function index($msg = NULL){
        $data['msg'] = $msg;
        $data['title'] ='Đăng Nhập Trang Admin';
        if(isset($_REQUEST["username"])){
            $Username = $_REQUEST["username"];
            $Password = $_REQUEST['password'];
            $result = $this->Musers->validateAdmin($Username, $Password);
            var_dump($result);
            if(! $result){
                $msg = "<div class='error'>Username hay Password không đúng</div>";
                $data['msg'] = $msg;
                $this->admin_login->view("admin/login",$data);
            } else {
                redirect('admin/home');
            } 
        } else {
            $this->admin_login->view("admin/login",$data);
        }
    }

    public function do_Logout(){
        $this->session->sess_destroy();
        redirect('admin/login');
    }

}
?>
